# -*- coding: utf-8 -*-

# 文件名： DesModule
# 日  期： 2023/4/17
# 你有见过洛杉矶凌晨4点的太阳和直升机上的肘击吗?
#                  —————By Black Mamba , Kobe Bryant

from pyDes import *
import binascii


def des_encrypt(s, key):
    secret_key = key
    iv = secret_key
    k = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5)
    en = k.encrypt(s, padmode=PAD_PKCS5)
    return binascii.b2a_hex(en).decode()


def des_decrypt(s, key):
    secret_key = key
    iv = secret_key
    k = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5)
    de = k.decrypt(binascii.a2b_hex(s), padmode=PAD_PKCS5)
    return de.decode()


if __name__ == "__main__":
    ciphertext = des_encrypt("Kun,you are so beautiful!", "1145141919810")
    print("密文：", ciphertext)
    plaintext = des_decrypt(ciphertext, "1145141919810"
                                        "+")
    print("解密后的明文：", plaintext)
